package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/brand")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> getBrandPageList(@PathVariable Integer page,@PathVariable Integer limit){
        PageInfo<Brand> pageInfo=brandService.getBrandPageList(page,limit);
        return Result.ok(pageInfo);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.ok(null);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.ok(null);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return Result.ok(null);
    }
    @GetMapping("/findAll")
    public Result<List<Brand>> findAll(){
        List<Brand> brandList= brandService.findAll();
        return Result.ok(brandList);
    }
}
